const mongoose = require('mongoose');
const reg = require('../utils/reg');

// 密码加密
const bcrypt = require('../utils/bcrypt');

// 5.创建文档的结构对象(设置对象数据类型格式)
let Accountchema = new mongoose.Schema({
  phone: {
    type: Number,
    required: true, //判断该字段必填
  },
  password: {
    type: String,
    set(val) {
      // 每次数据库进行修改或插入时都会执行set
      return bcrypt(val); // 对存入数据库的密码进行加密
    },
  },
  username: {
    type: String,
    default: '测试用户'
  },
});
// 6.创建模型对象
let AccountModel = mongoose.model('user', Accountchema);

module.exports = AccountModel
